#include "info.h"

Info::Info()
{

}
const QString Info::localmachineName()
{
    QString machineName = QHostInfo::localHostName();
    QString sufix=".local";
    machineName=machineName.mid(0,machineName.length()-sufix.length());
    return machineName;
}


const QString Info::cpuInfo()
{
    QProcess process(0);
    QString command;
    QStringList arguements;
#ifdef Q_OS_OSX
    command="sysctl";
    arguements<<"-n"<<"machdep.cpu.brand_string";
#endif
#ifdef Q_OS_WIN
    command="wmic";
    arguements<<"CPU";
#endif
#ifdef Q_OS_LINUX
    command="cat";
    arguements<<"/proc/cpuinfo";
#endif

    process.start(command,arguements);
    process.waitForStarted();
    process.waitForFinished();
    QString info=QString::fromLocal8Bit(process.readAllStandardOutput());
#ifdef Q_OS_WIN
    int nameIndex=info.indexOf(" Name ")+1;
    int numberOfCoresIndex=info.indexOf(" NumberOfCores ")+1;
    int firstLineLength=info.indexOf("\n")+1;
    info = info.mid(firstLineLength+nameIndex,numberOfCoresIndex-nameIndex);
#endif
#ifdef Q_OS_LINUX
    info=info.replace(QRegExp(".*model name\t:([^\n]*).*"),"\\1");
#endif
    return info;

}
